home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / ape-ad1a / frmmain.frm (.txt) < prev    next >
Visual Basic Form  |  1999-09-21  |  4KB  |  121 lines

  1. VERSION 5.00
  2. Begin VB.Form frmMain 
  3.    BackColor       =   &H00000000&
  4.    BorderStyle     =   0  'None
  5.    Caption         =   "APE Example"
  6.    ClientHeight    =   3600
  7.    ClientLeft      =   0
  8.    ClientTop       =   0
  9.    ClientWidth     =   4800
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   240
  12.    ScaleMode       =   3  'Pixel
  13.    ScaleWidth      =   320
  14.    StartUpPosition =   3  'Windows Default
  15.    WindowState     =   2  'Maximized
  16. Attribute VB_Name = "frmMain"
  17. Attribute VB_GlobalNameSpace = False
  18. Attribute VB_Creatable = False
  19. Attribute VB_PredeclaredId = True
  20. Attribute VB_Exposed = False
  21. Private Sub Form_KeyPress(KeyAscii As Integer)
  22.     ' If key ESC is pressed
  23.     If KeyAscii = 27 Then
  24.         ' If playing then pause the game
  25.         If Game.GameState = Game.GS_PLAYING Then Game.GameState = Game.GS_MENU: MIDIMusic.PlayIntro: DSoundCode.LoadMenuSounds: DSoundCode.PlayMenuAmbient
  26.         ' If paused, then resume the game
  27.         If Game.GameState = Game.GS_PAUSED Then Game.GameState = Game.GS_PLAYING
  28.         ' If we are exiting the game, quit completely
  29.         If Game.GameState = Game.GS_EXITING Then Unload Me
  30.     End If
  31. End Sub
  32. Private Sub Form_Load()
  33.     ' Current time and next time, frame limiter
  34.     Dim curTime As Long, nextTime As Long
  35.     ' Make sure the form is shown first
  36.     Me.Show
  37.     ' Initialise DirectDraw
  38.     DDrawCode.InitDDraw
  39.     ' Set up the credits scroller
  40.     DDrawCode.myCredits.PosY = DDrawCode.myScreen.m_PixelHeight
  41.     ' Load the credits text file
  42.     Game.LoadCreditsTXT
  43.     ' Create fixedsys font
  44.     Credits.myFont.CreateNewFont "Fixedsys"
  45.     ' Initialise GUID's for DInput
  46.     GUIDDEFS.GUID_Initialize
  47.     ' Initialise DirectInput
  48.     DInputCode.InitDInput
  49.     ' Initialise DirectSound
  50.     DSoundCode.InitDSound
  51.     ' Load the sounds for the menu
  52.     DSoundCode.LoadMenuSounds
  53.     ' Play ambient music in the menu
  54.     DSoundCode.PlayMenuAmbient
  55.     ' Set the game's current state to MENU
  56.     Game.GameState = Game.GS_MENU
  57.     ' Set the menu state to being on the "new" button
  58.     Game.MenuState = Game.MS_NEW_ON
  59.     ' Start up the MIDI music
  60.     MIDIMusic.PlayIntro
  61.     ' No level yet
  62.     Game.levelnumber = 0
  63.     ' Menu time delay
  64.     Game.TimeAddOn = 200
  65.     ' Frame limiting
  66.     nextTime = timeGetTime() + Game.TimeAddOn
  67.     ' Main game loop
  68.     Do While DoEvents()
  69.         ' Get the current time
  70.         curTime = timeGetTime()
  71.         
  72.         ' Compare current time to when loop should be executed
  73.         If curTime >= nextTime Then
  74.         
  75.             ' Calculate FPS
  76.             myFPS.GetFPS
  77.             
  78.             ' Render the game according to the game's state
  79.             Select Case Game.GameState
  80.                 ' Render the menu
  81.                 Case Game.GS_MENU:
  82.                     Game.TimeAddOn = 200
  83.                     DDrawCode.RenderMenu
  84.                 ' Render the paused screen
  85.                 Case Game.GS_PAUSED:
  86.                     DDrawCode.RenderPaused
  87.                 ' Render the actual game (map and stuff)
  88.                 Case Game.GS_PLAYING:
  89.                     Game.TimeAddOn = 10
  90.                     DDrawCode.RenderGame
  91.                 ' Render exit screen
  92.                 Case Game.GS_EXITING:
  93.                     Game.TimeAddOn = 50
  94.                     DDrawCode.RenderExit
  95.                 ' Load the next level
  96.                 Case Game.GS_LOADNEXTLEVEL:
  97.                     Game.levelnumber = Game.levelnumber + 1
  98.                     DDrawCode.RenderChangeLevel
  99.                     MIDIMusic.PlayLevelMusic Game.levelnumber
  100.                     Game.GameState = Game.GS_PLAYING
  101.                 ' Set up an entirely new game
  102.                 Case Game.GS_NEWGAME:
  103.                     Game.TimeAddOn = 100
  104.                     DDrawCode.InitMap
  105.                     Game.levelnumber = 0
  106.                     Game.GameState = Game.GS_LOADNEXTLEVEL
  107.             End Select
  108.             
  109.             ' Calculate next time loop is executed
  110.             nextTime = curTime + Game.TimeAddOn
  111.         End If
  112.     Loop
  113. End Sub
  114. Private Sub Form_Unload(Cancel As Integer)
  115.     ' Close down all of the DirectX stuff
  116.     DDrawCode.CloseDDraw
  117.     DInputCode.CloseDInput
  118.     DSoundCode.CloseDSound
  119.     MIDIMusic.myMusic.StopPlaying
  120. End Sub
  121.